package com.example.common.ui;

import android.app.Activity;
import com.example.common.widget.state.OnAnewRequestNetworkListener;
import com.example.common.widget.state.NetworkStateView;

/**
 * 网络状态Activity
 */
public abstract class NetworkStateActivity extends Activity implements OnAnewRequestNetworkListener, NetworkStateView {

//    private NetworkStateLayout mStateLayout;
//
//    @Override
//    public void setContentView(int layoutResID) {
//        LinearLayout rootView = (LinearLayout) View.inflate(this, R.layout.activity_network_state, null);
//
//        // 添加标题
//        int titleLayoutRes = getTitleLayoutRes();
//        if (titleLayoutRes != 0){
//            rootView.addView(LayoutInflater.from(this).inflate(titleLayoutRes, rootView, false), 0);
//        }
//
//        // 添加状态布局
//        mStateLayout = rootView.findViewById(R.id.mNetworkStateLayout);
//        mStateLayout.addView(LayoutInflater.from(this).inflate(layoutResID, mStateLayout, false));
//        super.setContentView(rootView);
//
//        // 重新请求网络监听
//        mStateLayout.setOnAnewRequestNetworkListener(this);
//    }
//
//    @Override
//    public void notNetwork() {
//        if (mStateLayout != null){
//            mStateLayout.showNetworkStateView(NetworkStateLayout.NOT_NETWORK_STATE);
//        }
//    }
//
//    @Override
//    public void loadingNetwork() {
//        if (mStateLayout != null){
//            mStateLayout.showNetworkStateView(NetworkStateLayout.LOADING_NETWORK_STATE);
//        }
//    }
//
//    @Override
//    public void successNetwork() {
//        if (mStateLayout != null){
//            mStateLayout.showContentView();
//        }
//    }
//
//    @Override
//    public void errorNetwork() {
//        if (mStateLayout != null){
//            mStateLayout.showNetworkStateView(NetworkStateLayout.ERROR_NETWORK_STATE);
//        }
//    }
//
//    @Override
//    public void emptyNetwork() {
//        if (mStateLayout != null){
//            mStateLayout.showNetworkStateView(NetworkStateLayout.EMPTY_NETWORK_STATE);
//        }
//    }
//
//    @Override
//    public void onAnewRequestNetwork() {
//        loadingNetwork();
//        new Handler(Looper.myLooper()).postDelayed(this::onAnewRequest, getResources().getInteger(R.integer.load_duration));
//    }
//
//    /**
//     * 获取标题布局
//     */
//    public @LayoutRes
//    int getTitleLayoutRes() {
//        return 0;
//    }
//
//    /**
//     * 重新请求网络
//     */
//    public abstract void onAnewRequest();
}
